from pyecharts import options as opts
from pyecharts.charts import Graph

nodes = [
    opts.GraphNode(name='节点1', symbol_size=40),
    opts.GraphNode(name='节点2', symbol_size=40),
    opts.GraphNode(name='节点3', symbol_size=40),
    opts.GraphNode(name='节点4', symbol_size=40),
    opts.GraphNode(name='节点5', symbol_size=40),
    opts.GraphNode(name='节点6', symbol_size=40),
    opts.GraphNode(name='节点7', symbol_size=40),
    opts.GraphNode(name='节点8', symbol_size=40),
    opts.GraphNode(name='节点9', symbol_size=40),
    opts.GraphNode(name='节点10', symbol_size=40)
]

links = [
    opts.GraphLink(source='节点1', target='节点2', value=2),
    opts.GraphLink(source='节点2', target='节点4'),
    opts.GraphLink(source='节点3', target='节点5'),
    opts.GraphLink(source='节点4', target='节点8'),
    opts.GraphLink(source='节点5', target='节点6'),
    opts.GraphLink(source='节点6', target='节点2'),
    opts.GraphLink(source='节点7', target='节点2'),
    opts.GraphLink(source='节点8', target='节点2'),
    opts.GraphLink(source='节点9', target='节点2'),
    opts.GraphLink(source='节点10', target='节点2'),
    opts.GraphLink(source='节点1', target='节点2'),
    opts.GraphLink(source='节点1', target='节点2'),
]

c = (
    Graph()
    .add(
        '',
        nodes,
        links,
        repulsion=4000,
        edge_label=opts.LabelOpts(
            is_show=True, position="middle", formatter="aaa{b} bbb"
        )
    )
    .set_global_opts(title_opts=opts.TitleOpts(title='Graph'))

)
c.render("D:/合胜/合胜/数据分析/myEcharts.html")
